<?php

namespace Models;

class DbContext {
    
    protected $_connection;
    
    protected static $_instance = null;
    
    public static function getConnection() {
        
        if (!self::$_instance) {
            self::$_instance = new self();
        }
        
        return self::$_instance->_connection;
    }
    
    protected function __construct() {
        try {
            $this->_connection = new \PDO("mysql:dbname=test", 'root', 'root');
            $this->_connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
        } catch (\PDOException $e) {
            echo $e->getMessage();
        }
    }
}

